#include <deviceOperateSN.h>
#include <genrand.h>
uint8_t MCU_XDATA_TYPE deviceSnString[DEVICE_SERIAL_NUMBER_SIZE];
#define SN_USE_DEVICE_GEN 1
#define DEVICE_SN_PC_CHECK_SAVE_FILE "./deviceSnSave.txt"
// ===coding by user self===
void deviceSnReadFormHardware()
{
#if SN_USE_DEVICE_GEN
    int tmpflag = 0;// = readLocalFile(DEVICE_SN_PC_CHECK_SAVE_FILE, (char *)deviceSnString, sizeof(deviceSnString));
    memset(deviceSnString, 0, sizeof(deviceSnString));
    if(tmpflag <= 0)
    {
        generatorRandHexBuffer(deviceSnString, sizeof(deviceSnString));
        // writeLocalFile(DEVICE_SN_PC_CHECK_SAVE_FILE, (char *)deviceSnString, sizeof(deviceSnString));
    }
#else
    memset(deviceSnString, 0, sizeof(deviceSnString));
    readLocalFile(DEVICE_SN_PC_CHECK_SAVE_FILE, (char *)deviceSnString, sizeof(deviceSnString));
#endif
    logdebug("read sn:%s", getMaxSizeHexStr(deviceSnString).byteStr);

}

void deviceSnSaveToHardware(const char *setsn)
{
#if SN_USE_DEVICE_GEN
    setsn = NULL;
#else
    memcpy(deviceSnString, setsn, sizeof(deviceSnString));
    writeLocalFile(DEVICE_SN_PC_CHECK_SAVE_FILE, (char *)deviceSnString, sizeof(deviceSnString));
#endif
    logdebug("save sn:%s", getMaxSizeHexStr(deviceSnString).byteStr);
}
